<template>
     <div>

        <myheader></myheader>

      <br><br>
      <!--面包屑导航-->
      <Breadcrumb :datas="datas"></Breadcrumb>

	<section class="featured-block text-center">
		<div class="container">
      <table>
        <tr>
          <td>商品名称</td>
          <td><input type="text" v-model="name"></td>
        </tr>

        <tr>
          <td>商品标签</td>
            <TagInput v-model="mytags" type="string" split="," placeholder="输入标签，英文逗号分隔，输入完毕回车确认"></TagInput>
        </tr>

        <tr>
          <td>商品简介</td>
          <td>
            <input type="text" v-model="desc">
          </td>
        </tr>

        <tr>
          <td>颜色</td>
          <td>
              <input type="text" v-model="color">
          </td>
        </tr>
        <tr>
          <td>号码</td>
          <td>
              <input type="text" v-model="size">
          </td>
        </tr>
        <tr>
          <td>季节</td>
          <td>
              <input type="text" v-model="season">
          </td>
        </tr>

        <tr>
          <td>价格</td>
          <td>
              <input type="text" v-model="price">
          </td>
        </tr>

        <tr>
          <td><Button @click="submit" color="green">提交</Button></td>
        </tr>

      </table>

		</div>
	</section>





	<myempennage></myempennage>

  </div>

</template>

<script>
        import myheader from './myheader'
  import myempennage from './myempennage'
    export default {
        name: "addgoods",
      data(){
          return{
            datas:[{title:'首页', route:{name:'index'}}, {title:'添加商品'}],
            name:'',
            desc:'',
            color:'',
            size:'',
            season:'',
            price:0,
            cate_id:1,
            mytags:'',
          }
      },
      // 注册组件标签
      components:{
        'myheader': myheader,
        'myempennage': myempennage,
      },

        mounted:function(){

      },
        methods: {


          // 提交
          submit:function(){


            //拼接商品规格
            var parms = {};
            parms['color'] = this.color;
            parms['size'] = this.size;
            parms['season'] = this.season;
            // console.log(parms);

            //格式化字符串
            parms = JSON.stringify(parms);
            // console.log(parms);

            //从字符串转回json
            // parms = JSON.parse(parms);
            // console.log(parms)

            // 发送请求
            this.axios.get(
              'http://127.0.0.1:8000/insertgoods/',{params:{name:this.name,desc:this.desc,parms:parms,price:this.price,cate_id:this.cate_id}}).then(res=>{
                console.log(res);
                this.$Message(res.data.msg);

              // 只有商品入库成功才能添加标签
              if(res.data.id) {
                // 标签分类嵌套发送请求    id是商品ID  联动添加
                this.axios.get(
                  'http://127.0.0.1:8000/inserttags/', {params: {id: res.data.id, tags: this.mytags}}).then(res => {
                  console.log(res);
                });
              }
            });


          },
        }

    }
</script>

<style scoped>

</style>
